package com.yunxin.core.utils.infra.common.constant;

import com.yunxin.common.result.IResultCode;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.io.Serializable;
/**
 * @author zero°
 * @since 2023-05-26
 */
@AllArgsConstructor
@NoArgsConstructor
public enum ServerResultCode implements IResultCode, Serializable {


    /**
     * 成功
     */
    SUCCESS("00000", "成功"),

    SYSTEM_EXECUTION_ERROR("B0001", "系统执行出错"),

    MERCHANT_STATUS_ERROR("BM0001", "商户状态原状态一致"),

    ADMIN_USER_STATUS_ERROR("BU0001", "用户已冻结"),


    ;

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    private String code;

    private String msg;

    @Override
    public String toString() {
        return "{" +
                "\"code\":\"" + code + '\"' +
                ", \"msg\":\"" + msg + '\"' +
                '}';
    }


    public static ServerResultCode getValue(String code) {
        for (ServerResultCode value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        // 默认系统执行错误
        return SYSTEM_EXECUTION_ERROR;
    }
}